package com.zy.openchat.core.model.photo;

import android.os.Parcel;
import android.os.Parcelable;

import com.zy.openchat.core.model.file.FileInfo;

import org.apache.commons.lang3.StringUtils;

public class ThumbnailInfo implements Parcelable {
    public float width;
    public float height;
    public FileInfo file;
    public ThumbnailFormatInfo format;

    public boolean isThumbnailDownloaded() {
        if (file != null && file.local != null) {
            return file.local.is_downloading_completed && !StringUtils.isEmpty(file.local.path);
        }
        return false;
    }

    public String localPath() {
        if (file != null && file.local != null && file.local.isExist()) {
            return file.local.path;
        }
        return null;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeFloat(this.width);
        dest.writeFloat(this.height);
        dest.writeParcelable(this.file, flags);
        dest.writeParcelable(this.format, flags);
    }

    public ThumbnailInfo() {
    }

    protected ThumbnailInfo(Parcel in) {
        this.width = in.readFloat();
        this.height = in.readFloat();
        this.file = in.readParcelable(FileInfo.class.getClassLoader());
        this.format = in.readParcelable(ThumbnailFormatInfo.class.getClassLoader());
    }

    public static final Creator<ThumbnailInfo> CREATOR = new Creator<ThumbnailInfo>() {
        @Override
        public ThumbnailInfo createFromParcel(Parcel source) {
            return new ThumbnailInfo(source);
        }

        @Override
        public ThumbnailInfo[] newArray(int size) {
            return new ThumbnailInfo[size];
        }
    };
}
